/*****Log*****/
clear
cd "C:\Users\Joshua\Dropbox\Work\Networks and Economic Perceptions\Data and Do Files"
	/*you will need to update the above to point to where you have the data and 
	cleaning files*/

log using "Appendix E - Matching Output.smcl", replace
	/*the log file is in format .smcl, but can be read via txt editor*/
	


/***********************************************************************
************************************************************************
************************************************************************
This do file contains the needed to replicate our Online Appendix E: 
Matching.  

For each survey, the code will load and clean the data at hand using the
commands included in the survey cleaning .do files and then do the 
analyses in question. For those wishing to use this to replicate the analyses, 
you will need to update the cd command below to point to where your data
and .do files are located. 

Also note that the following STATA modules need to be installed: 

ssc install estout, replace
ssc install grc1leg, replace
ssc install ebalance, replace
ssc install blindschemes, replace

************************************************************************
************************************************************************
***********************************************************************/
	
/****************************************
*****************************************
		2000 ANES
*****************************************
****************************************/	

/*Data Cleaning*/
clear
do "Data Cleaning - 2000 ANES.do"
set more off


/*Splitting the Disagreement Variable*/
summ disagree_total, detail
	*median= -1

gen disagree_split = .
replace disagree_split = 1 if disagree_total >= 0 & disagree_total <= 4
replace disagree_split = 0 if disagree_total >= -4 & disagree_total <= -2
tab disagree_split
label var disagree_split "Disagreement" 
label def split11 1 "High Disagreement" 0 "Low Disagreement" 
label values disagree_split split11


/*Entropy balancing*/
tabulate race, gen(rac)
tabulate educ, gen(edu)
tabulate pid_str, gen(pidstr)

ebalance disagree_split evaluate1 nfc1 conflicting consistent pidstr2 pidstr3 ideology camp_int interest ///
	knowl gender rac2 rac3 edu2 edu3 edu4 age marital

svyset [pweight = _webal]

/*Analyses*/

*Knowledge*
eststo clear
eststo: svy: logit def_knowl i.disagree_split##i.partisan
	margins, dydx(disagree_split) by(partisan)
	
	margins partisan, by(disagree_split)
	marginsplot, ylabel(0(0.2)1) by(partisan) scheme(plotplain) ytitle("Pr(Correct on  Deficit)") ///
		byopts(title("Deficit Knowledge: Predicted Probabilities")) recast(bar) xlabel(0 "Low" 1 "High")
	
	graph save "2000 - knowl ebal", replace
	
eststo: svy: ologit econ_post3 i.disagree_split##i.partisan
	margins, dydx(disagree_split) by(partisan) predict(outcome(3))
	
	margins partisan, by(disagree_split) predict(outcome(3)) 
	marginsplot, ylabel(0(0.2)1) by(partisan) scheme(plotplain) ytitle("Pr(Better)") ///
		byopts(title("Economic Evaluation: Probability of Saying Better")) recast(bar) xlabel(0 "Low" 1 "High")
			
	graph save "2000 - econ ebal", replace
	
	grc1leg "2000 - knowl ebal" "2000 - econ ebal", scheme(plotplain) 
	graph save "Figure OC1 - 2000 Ebal Results", replace
	graph export "Figure OC1 - 2000 Ebal Results.png", replace
	
esttab using 2000EBAL.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("Deficit Knowledge" "Econ. Evals") ///
	title({\b Table OC1.} "2000 ANES - Entropy Balancing Results")  ///
	se 


eststo clear
	

/****************************************
*****************************************
		2002 ANES
*****************************************
****************************************/	

/*Data Cleaning*/
clear
do "Data Cleaning - 2002 ANES.do"
set more off


/*Splitting the Disagreement Meausre*/

summ disagree_total, detail
	*median = -1
gen disagree_split = . 
replace disagree_split = 1 if disagree_total >=0 & disagree_total <=4
replace disagree_split = 0 if disagree_total >= -4 & disagree_total <= -2
tab disagree_split
label var disagree_split "Disagreement" 
label def split11 1 "High Disagreement" 0 "Low Disagreement" 
label values disagree_split split11

/*Entropy Balancing*/
tabulate race, gen(rac)
tabulate educ2000, gen(edu)
tabulate pid_str2000, gen(pidstr)

ebalance disagree_split evaluate1 nfc1 pidstr2 pidstr3 conflicting consistent ideology knowl  ///
	camp_int2000 follow rac2 rac3 rac4 gender edu2 edu3 edu4 marital2000 age2000

svyset [pweight = _webal]

/*Analyses*/

*P. Extremity*
eststo clear
eststo: svy: ologit pid_str_full i.disagree_split 
	margins, dydx(disagree_split) predict(outcome(4))
	margins disagree_split, predict(outcome(4))
	
	marginsplot, ylabel(0(0.2)1) scheme(plotplain) ytitle("Pr(Better)") ///
		title("Economic Evaluation: Probability of Saying Better") recast(bar) xlabel(0 "Low" 1 "High")
	
*Econ. Eval*
eststo: svy: ologit retro2002_3 i.disagree_split##i.partisan
	margins, dydx(disagree_split) by(partisan) predict(outcome(3))
	
	margins partisan, by(disagree_split)  predict(outcome(3))

esttab using 2002EBAL.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("Partisan Extremity" "Econ. Evals") ///
	title({\b Table OC2.} "2002 ANES - Entropy Balancing Results")  ///
	se 
eststo clear
	


/****************************************
*****************************************
		2006 ANES
*****************************************
****************************************/	

/*Data Cleaning*/
clear
do "Data Cleaning - 2006 ANES.do"


/*Splitting Disagreement*/
summ disagree_total, detail
	*median: -1

gen disagree_split = . 
replace disagree_split = 1 if disagree_total >= 0 & disagree_total <= 3
replace disagree_split = 0 if disagree_total >=-3 & disagree_total <=-2
tab disagree_split
label var disagree_split "Disagreement" 
label def split11 1 "High Disagreement" 0 "Low Disagreement" 
label values disagree_split split11
	
/*Entropy Balancing*/
tabulate pid_str2004, gen(pidstr)
tabulate educ, gen(edu)

ebalance disagree_split nfc1 evaluate1 pidstr2 pidstr3 consistent conflicting ///
	age2004 gender follow04 marital ideol  rac_2 rac_3 edu2 edu3 edu4 knowl04 follow04

svyset [pweight = _webal]

/*analyses*/

*partisan extremity
eststo clear
eststo: svy: ologit  pid_str_full i.disagree_split
	margins, dydx(disagree_split) predict(outcome(4))
	
*economic evaluations
eststo: svy: ologit retro i.disagree_split##i.partisan
	margins partisan, by(disagree_split) predict(outcome(3))
	margins, dydx(disagree_split) by(partisan) predict(outcome(3))
	
esttab using 2006EBAL.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("Partisan Extremity" "Econ. Evals") ///
	title({\b Table OC3.} "2006 ANES - Entropy Balancing Results")  ///
	se 


/****************************************
*****************************************
		2008-9 ANES
*****************************************
****************************************/	

/*Data Cleaning*/
clear
do "Data Cleaning - 2008 Panel.do"


/*Splitting Disagreement*/
summ disagree_total, detail
	*Median = -1
	
gen disagree_split = . 
replace disagree_split = 1 if disagree_total >=0 & disagree_total <=3
replace disagree_split = 0 if disagree_total >= -3 & disagree_total <= -2
tab disagree_split
label var disagree_split "Disagreement" 
label def split11 1 "High Disagreement" 0 "Low Disagreement" 
label values disagree_split split11


/*Entropy balancing*/

recode DER09W2 (-7 -6 -5 = .), gen(ideol)

ebalance  disagree_split nfc1 evaluate1 consistent_w2 conflicting_w2  ///
	ideol interest_w1 gender i.educ i.race i.pid_str1 marital knowl



svyset [pweight = _webal]


/*Analyses*/
*partisan extremity*
eststo clear
eststo: svy: ologit pid_str10_full i.disagree_split 
eststo: svy: ologit pid_str11_full i.disagree_split 
eststo: svy: ologit pid_str17_full i.disagree_split 
eststo: svy: ologit pid_str19_full i.disagree_split 
esttab using 2008EBAL_PEXTREME.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("W10" "W11" "W17" "W19") ///
	title({\b Table OC4.} "2008-2009 ANES - Entropy Balancing Results - Partisan Extremity")  ///
	se 

*partisan ambivalence*
eststo clear
eststo: svy: ologit in_like_w11 i.disagree_split 
eststo: svy: ologit in_dislike_w11 i.disagree_split 
eststo: svy: ologit out_like_w11 i.disagree_split 
eststo: svy: ologit out_dislike_w11 i.disagree_split 
esttab using 2008EBAL_PAMBIV.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("In:Fav." "In:Unfav." "Out:Fav." "Out:Unfav.") ///
	title({\b Table OC5.} "2008-2009 ANES - Entropy Balancing Results - Partisan Ambivalence")  ///
	se 



**knowledge and economic evaluations*
*knowledge*
eststo clear
eststo: svy: logit def_knowl17 i.disagree_split##i.partisan_9rev
	margins, dydx(disagree_split) by(partisan_9rev)
	margins partisan_9rev, by(disagree_split)
	
eststo: svy: logit def_knowl19 i.disagree_split##i.partisan_9rev
	margins, dydx(disagree_split) by(partisan_9rev)
	margins partisan_9rev, by(disagree_split)
	
eststo: svy: ologit w17_retro i.disagree_split##i.partisan_9rev
	margins, dydx(disagree_split) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, by(disagree_split) predict(outcome(3))
	
eststo: svy: ologit w19_retro i.disagree_split##i.partisan_9rev
	margins, dydx(disagree_split) by(partisan_9rev) predict(outcome(3))
	margins partisan_9rev, by(disagree_split) predict(outcome(3))

esttab using 2008EBAL_KNOWLECON.rtf, onecell nobaselevels replace label star(+ 0.10 * 0.05 ** 0.01) ///
	mtitles("W17:Knowl." "W19:Knowl." "W17:Econ." "W19:Econ.") ///
	title({\b Table OC6.} "2008-2009 ANES - Entropy Balancing Results - Knowledge & Econ Evals")  ///
	se 


	
log close
